package org.matchit.matcher.collection;

import java.util.Map;
import java.util.Map.Entry;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

public class EntryValueMatcher<V> extends TypeSafeMatcher<Map.Entry<?, V>> {
    private final Matcher<V> valueMatcher;

    public EntryValueMatcher(Matcher<V> valueMatcher) {
        this.valueMatcher = valueMatcher;
    }

    public static <V> EntryValueMatcher<V> hasValue(Matcher<V> valueMatcher) {
        return new EntryValueMatcher<V>(valueMatcher);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected boolean matchesSafely(Entry<?, V> entry) {
        return valueMatcher.matches(entry.getValue());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void describeTo(Description description) {
        description.appendText("has entry value ").appendDescriptionOf(valueMatcher);
    }

}
